import { createStore } from "vuex";
import { getArticleList, getArticleById } from "@/api/index.js";

//Mutation改变状态

export default createStore({
  state: {
    carouseList: null,
    overview: null, //概况
    scopeList: null, //业务范围
    teamLeaderList: null, //团队领导
    contact: null, //联系方式
  },
  getters: {
    getCarouseList: (state) => {
      return state.carouseList;
    },
    getOverview: (state) => {
      return state.overview;
    },
    getScopeList: (state) => {
      return state.scopeList;
    },
    getTeamLeaders: (state) => {
      return state.teamLeaderList;
    },
    getContact: (state) => {
      return state.contact;
    },
  },
  mutations: {
    //轮播图
    setCarouseList(state, carouseList) {
      state.carouseList = carouseList;
    },
    //概况
    setOverview(state, overview) {
      state.overview = overview;
    },
    //概况
    setScopeList(state, scopeList) {
      state.scopeList = scopeList;
    },
    //团队领导
    setTeamLeaders(state, teamLeaderList) {
      state.teamLeaderList = teamLeaderList;
    },
    //联系方式
    setContact(state, contact) {
      state.contact = contact;
    },
  },
  actions: {
    async getCarouseList({ commit, state }, payload) {
      var params = {
        categoryId: "1508341156335935489",
        contentDisplay: "0",
      };
      let res = await getArticleList(params);
      if (res.code == 200) {
        var carouseList = res.data.rows;
        carouseList = carouseList.sort(function (a, b) {
          return a.contentSort - b.contentSort;
        });
        commit("setCarouseList", carouseList);
      }
    },
    getOverview({ commit, state }, payload) {
      getArticleById("1504745115686592514").then((res) => {
        var overview = res.data;
        commit("setOverview", overview);
      });
    },
    async getScopeList({ commit, state }, payload) {
      var params = {
        categoryId: "1505109216107487234",
        contentDisplay: "0",
      };
      let res = await getArticleList(params);
      if (res.code == 200) {
        var scopeList = res.data.rows;
        scopeList = scopeList.sort(function (a, b) {
          return a.contentSort - b.contentSort;
        });
        commit("setScopeList", scopeList);
      }
    },
    getTeamLeaders({ commit, state }, payload) {
      var params = {
        categoryId: "1504496103238721538",
        contentDisplay: "0",
      };
      getArticleList(params).then((res) => {
        var teamLeaderList = res.data.rows;
        teamLeaderList = teamLeaderList.sort(function (a, b) {
          return a.contentSort - b.contentSort;
        });
        commit("setTeamLeaders", teamLeaderList);
      });
    },
    async getContact({ commit, state }, payload) {
      let res = await getArticleById("1505748249888251906");
      if (res.code == 200) {
        var contact = res.data;
        commit("setContact", contact);
      }
    },
  },
  modules: {},
});
